/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.gov.cemaden.library.dao.smp;

import br.gov.cemaden.library.dao.GenericDao;
import br.gov.cemaden.library.interfaces.smp.LogRedeInterface;
import br.gov.cemaden.library.model.pcds.Rede;
import br.gov.cemaden.library.model.smp.LogRede;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author alan
 */
public class LogRedeDao extends GenericDao implements LogRedeInterface {

    Session session;

    public LogRedeDao(Session session) {
        this.session = session;
    }

    public List<LogRede> findAll() {
        List<LogRede> list = null;
        try {
            Query query = session.getNamedQuery("LogRede.findAll");
            list = query.list();
        } catch (HibernateException ex) {
            throw ex;
        }
        return list;
    }

    public List<LogRede> findByRede(Rede rede) {
        List<LogRede> list = null;
        try {
            Query query = session.getNamedQuery("LogRede.findByRede").setParameter("rede", rede);
            list = query.list();
        } catch (HibernateException ex) {
            throw ex;
        }
        return list;
    }

    public void insert(LogRede log) {
        
        try{
            saveOrUpdate(session, log);
        }catch(Exception ex){
            throw new HibernateException(ex);
        }                
    }

}
